
import {getItemsSummary} from '~/server/database/repositories/itemOperation'
import {getUserFromJwt} from '~/utils/serveCommon'
import {Prisma} from '@prisma/client'
export default defineEventHandler(async (context) => {
  try{
    const paramData = getQuery(context) || {}
    const {happened_after,happened_before,group_by,kind} =paramData
    if(!happened_after || !happened_before || !group_by || !kind){
      return sendError(context,createError({
        statusCode: 400,
        statusMessage: '参数错误!',
      }))
    }
    const user_id = getUserFromJwt(context)
    return await getItemsSummary(happened_after as string,happened_before as string,group_by as Prisma.ItemScalarFieldEnum,kind as TagType,user_id)
  }catch(error){
    return sendError(context, createError({
      statusCode: 400,
      statusMessage: '获取数据失败!',
    }))
  }
})